<template>
  <div>
    <el-select popper-class="ft-project-select"
               v-if="true" v-model="contNum" value-key="contNum"
               :placeholder="placeholder"
               @change="selectCont">
      <el-option
          v-for="item in contList"
          :key="item.contNum"
          :disabled="item.status=='true'"
          :label="item.contNum"
          :value="item">
      </el-option>
    </el-select>
    <span style="color: red ;font-size: 12px" v-if='!this.str.includes("false") && this.str.length!=0'>该项目下所属合同均已被关联</span>
  </div>
</template>

<script>
export default {
  name: "FtContInfo",
  props: {
    placeholder: {
      type: String,
      default: '请选合同'
    },
    projectId:{
      type: String
    },
    value: {
      type: String
    },
    editable: {
      type: Boolean,
      default: true
    },
  },
  mounted() {
    if(this.projectId){
      this.request()
    }
  },
  data() {
    return {
      contList: {},
      contInfo:null,
      isShow:false,
      str:[],
      contNum:this.value
    }
  },
  methods: {
    request(val) {
      this.loading = true
      val = val || this.projectId
      let url =  "/joys-rest/ncls-bms/contract/getCont/"
      this.$http.post(url+val).then(resp => {
        this.contList = resp.body
        if(this.contList){
          this.contList.find(item=>{
            if(item.status=="false"){
              this.contNum = item.contNum
              return this.$emit("contNumMethod",item.contNum)
            }
          })
          this.contList.forEach(item=>{
            this.str.push(item.status)
          })
        }
        this.merge()
        this.loading = false
      })
    },
    selectCont(val) {
      this.projectId = this.projectId
      this.$emit("contNumMethod",val.contNum)
    },
    merge() {
      this.projectId && this.contList.forEach((item) => {
        this.contInfo = item
      })
    },
    crearData(){
      if(this.contInfo){
        this.contInfo = {};
      }
    },
  },

  watch: {
    value(newVal) {
      this.projectId = newVal
    }
  }
}
</script>

<style>
.ft-project-select .el-select-dropdown__item {
  padding: 4px 20px;
  font-size: 14px;
  line-height: 21px;
  height: auto;
}
</style>